package com.qf.blog.interceptor;

import com.qf.blog.constatns.LoginConstatns;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class IsLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //System.out.println("IsLoginIntrerceptor.preHandle,"+request.getRequestURI());

        Object user = request.getSession().getAttribute(LoginConstatns.LOGIN_USER_KEY);
        if (user != null) {
        return true;
        }
        response.sendRedirect(request.getServletContext().getContextPath()+"/site/login.html");
        return false;
    }
}
